#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version        : 1.0
# @Create Time    : 2024/9/6 11:11
# @File           : feature
# @IDE            : PyCharm
# @desc           : 描述
from datetime import datetime
from typing import List

from sqlalchemy.orm import Mapped, mapped_column, relationship
from db.db_base import BaseModel, AuditModel
from sqlalchemy import JSON, String, DateTime, ForeignKey, Integer, Text, Boolean


class DCQAR(AuditModel):
    __tablename__ = "dc_check_qar"
    __table_args__ = ({'comment': 'QAR检验主表'})

    qar_no: Mapped[str] = mapped_column(String(20), unique=True, index=True, comment="QAR编号")
    asr_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="ASR检验编号, QAR编号+ASR")
    pclr_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="PCLR检验编号, QAR编号+PCLR")
    ndt_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="NDT检验编号, QAR编号+NDT")

    question_no: Mapped[str] = mapped_column(String(30), nullable=True, comment="问题单编号")
    question_status: Mapped[str] = mapped_column(String(30), nullable=True, comment="问题单状态")
    frr_no: Mapped[str] = mapped_column(String(30), nullable=True, comment="FRR编号")
    correct_no: Mapped[str] = mapped_column(String(30), nullable=True, comment="纠正措施项目编号")

    form_type: Mapped[str] = mapped_column(String(100), nullable=True, comment="表单类型, 系统根据零件类型判断并带出")
    status: Mapped[str] = mapped_column(String(20), nullable=True, comment="当前状态")

    #################  SAP接口获取字段 ###########################
    purchase_order: Mapped[str] = mapped_column(String(100), nullable=True, comment="采购订单号")
    flight: Mapped[str] = mapped_column(String(30), nullable=True, comment="架次")
    quantity_weight: Mapped[str] = mapped_column(String(20), nullable=True, comment="到货数量/重量")
    vendor: Mapped[str] = mapped_column(String(40), nullable=True, comment="销售商")
    ##############################################################
    manufacturer: Mapped[str] = mapped_column(String(40), nullable=True, comment="制造商")
    
    product_type: Mapped[str] = mapped_column(String(20), nullable=True, comment="产品类型")

    part_type: Mapped[str] = mapped_column(String(20), nullable=True, comment="材料/零件类型")
    part_no: Mapped[str] = mapped_column(String(40), comment="材料/零件图号")
    part_name: Mapped[str] = mapped_column(String(40), comment="零件名称")
    material_no: Mapped[str] = mapped_column(Text, comment="物料编号")

    # 物料主数据带入
    rev_letter: Mapped[str] = mapped_column(String(20), nullable=True, comment="更改字母")
    temper: Mapped[str] = mapped_column(String(20), nullable=True, comment="物料状态")
    zpm_cpm: Mapped[str] = mapped_column(String(20), nullable=True, comment="工艺材料编号")
    typing: Mapped[str] = mapped_column(String(20), nullable=True, comment="型别")
    classing: Mapped[str] = mapped_column(String(20), nullable=True, comment="类别/组合物别")
    grade: Mapped[str] = mapped_column(String(20), nullable=True, comment="级别")
    form: Mapped[str] = mapped_column(String(20), nullable=True, comment="形式/形态")
    size: Mapped[str] = mapped_column(String(20), nullable=True, comment="规格")
    color: Mapped[str] = mapped_column(String(20), nullable=True, comment="色号")
    material_type: Mapped[str] = mapped_column(String(20), nullable=True, comment="物料类型")

    ########################## 质量计划人员填写字段 #############################################
    spec_stan: Mapped[str] = mapped_column(String(20), nullable=True, comment="规范/标准")
    spec_stan_rev: Mapped[str] = mapped_column(String(20), nullable=True, comment="规范/标准版次")

    mat_code: Mapped[str] = mapped_column(String(20), nullable=True, comment="MAT号")
    test_items: Mapped[str] = mapped_column(String(20), nullable=True, comment="试验项数")
    required_dimension: Mapped[str] = mapped_column(String(40), nullable=True, comment="要求尺寸")
    pclr_quantity: Mapped[str] = mapped_column(String(20), nullable=True, comment="试样数量")
    pclr_size: Mapped[str] = mapped_column(String(20), nullable=True, comment="试样规格/尺寸")

    plan_remark: Mapped[str] = mapped_column(String(100), nullable=True, comment="计划备注")
    life_limit_req: Mapped[str] = mapped_column(String(20), nullable=True, comment="限寿工程要求")
    life_limit_date: Mapped[datetime] = mapped_column(DateTime, nullable=True, comment="基准日期，检验人员填写")
    life_limit_period: Mapped[str] = mapped_column(String(20), nullable=True, comment="限寿库房存储期限")
    life_limit_manage: Mapped[str] = mapped_column(String(20), nullable=True, comment="限寿管控方式")
    
    special_property: Mapped[str] = mapped_column(String(20), nullable=True, comment="性能要求")
    change_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="更改号或其他补充标识")
    draw_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="图号")
    draw_no_rev: Mapped[str] = mapped_column(String(20), nullable=True, comment="图号版次")
    software_code: Mapped[str] = mapped_column(String(20), nullable=True, comment="软件件号")
    software_rev: Mapped[str] = mapped_column(String(20), nullable=True, comment="软件版次")

    atp_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="ATP编号")
    atp_rev: Mapped[str] = mapped_column(String(20), nullable=True, comment="ATP版本")

    is_insp: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否检验")
    is_test: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否试验")
    is_sampling: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否抽样")
    is_life_limit: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否限寿件")
    is_correct_order: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否纠正委托")

    ########################## 检验人员填写字段 #############################################
    insp_remark: Mapped[str] = mapped_column(String(100), nullable=True, comment="检验备注")
    act_measurement: Mapped[str] = mapped_column(String(20), nullable=True, comment="实际测量, 对应要求尺寸")

    product_information: Mapped[str] = mapped_column(String(40), nullable=True, comment="实物信息")
    product_no: Mapped[str] = mapped_column(String(40), nullable=True, comment="所属成品件")
    product_name: Mapped[str] = mapped_column(String(40), nullable=True, comment="所属成品件名称")
    product_msn: Mapped[str] = mapped_column(String(40), nullable=True, comment="成品件序列号/批次")

    # 检验人员填写
    serial_no: Mapped[str] = mapped_column(String(200), nullable=True, comment="序列号")
    lot_batch_no: Mapped[str] = mapped_column(String(200), nullable=True, comment="炉批号")
    act_part_rev: Mapped[str] = mapped_column(String(20), nullable=True, comment="实际零件版次")
    act_change_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="实际更改号或其他补充标识")
    
    act_draw_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="实际图号")
    act_draw_no_rev: Mapped[str] = mapped_column(String(20), nullable=True, comment="实际图号版次")
    act_software_code: Mapped[str] = mapped_column(String(20), nullable=True, comment="实际软件件号")
    act_software_rev: Mapped[str] = mapped_column(String(20), nullable=True, comment="实际软件版本")
    act_atp_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="实际ATP编号")
    act_atp_rev: Mapped[str] = mapped_column(String(20), nullable=True, comment="实际ATP版本")

    # 质检人员填写
    actual_weight: Mapped[str] = mapped_column(String(20), nullable=True, comment="实际重量")
    source_of_weight: Mapped[str] = mapped_column(String(20), nullable=True, comment="重量来源")
    acceptable_quant: Mapped[str] = mapped_column(String(20), nullable=True, comment="合格数")
    rejective_quant: Mapped[str] = mapped_column(String(20), nullable=True, comment="拒收数")
    conformity_rate: Mapped[str] = mapped_column(String(20), nullable=True, comment="合格率, 系统计算")

    prepared_by: Mapped[str] = mapped_column(String(50), nullable=True, comment="质量计划人员")
    # prepared_datetime: Mapped[datetime] = mapped_column(DateTime, nullable=True, comment="质量计划时间")

    inspected_by: Mapped[str] = mapped_column(String(50), nullable=True, comment="质量质检人员")
    # inspected_datetime: Mapped[datetime] = mapped_column(DateTime, nullable=True, comment="质量质检时间")

    ok_to_file: Mapped[str] = mapped_column(String(10), nullable=True, comment="准予归档, 系统计算")
    changes: Mapped[str] = mapped_column(Text, nullable=True, comment="更改情况")
    attachment: Mapped[str] = mapped_column(Text, nullable=True, comment="附件地址")

    splited_by: Mapped[str] = mapped_column(String(50), nullable=True, comment="拆分人员")
    # splited_datetime: Mapped[datetime] = mapped_column(DateTime, nullable=True, comment="拆分时间")

    contents: Mapped[List[dict]] = mapped_column(JSON, nullable=True, default=[], comment="检验特性")


# class DCQARContent(AuditModel):
#     __tablename__ = "dc_check_qar_female_content"
#     __table_args__ = ({'comment': 'QAR检验内容表'})

#     qar_id: Mapped[int] = mapped_column(
#         Integer,
#         ForeignKey("dc_check_qar.id", ondelete='CASCADE'),
#         comment="QAR ID"
#     )
#     qar: Mapped[DCQAR] = relationship(foreign_keys=qar_id, back_populates='contents')

#     content_type: Mapped[str] = mapped_column(String(20), comment="类型")
#     project: Mapped[str] = mapped_column(String(40), comment="项目")
#     detail: Mapped[str] = mapped_column(String(60), nullable=True, comment="项目明细")
#     attachment: Mapped[str] = mapped_column(Text, nullable=True, comment="附件")
#     remark: Mapped[str] = mapped_column(Text, nullable=True, comment="备注")
#     is_pass: Mapped[bool] = mapped_column(Boolean, nullable=True, comment="检验结果，是否合格")


